<?php

namespace App\Http\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Crypt;

class Supp extends Model
{
    protected $table = 'supp';		//related table name
    protected $guarded = [];

    /**
     * 获取供应商的商品
     */
    public function shopGoods()
    {
        return $this->hasMany('App\Http\Model\ShopGoods','supp_id');
    }



    //访问器：获取用户的密码自动转换解密密码
    public function getPswAttribute($value)
    {
        try {
            return $value;
        } catch (DecryptException $e) {
            throw $e;
        }
    }


    //修改器：给用户的密码加密
    public function setPswAttribute($value)
    {
        $this->attributes['psw']=bcrypt($value);
    }

    //关联商品
    public function goods()
    {
        return $this->belongsToMany('App\Http\Model\PtGoods','goods_id');
    }

}
